package repositories;

import java.util.Collection;


import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Project;

@Repository
public interface ProjectRepository extends JpaRepository<Project,Integer>{
	
	// List the non finished projects
	@Query("select p from Project p where p.state <> \"finished\"")
	Collection<Project> findNonFinishedProjects();
	
	// List the projects that belongs to a specific user
	@Query("select p from Project p where p.creator.id = ?1")
	Collection<Project> findProjectsByCreatorId(int userId);
	
	// List the projects in which a user participates 
	@Query("select r.project from Registration r where r.user.id = ?1")
	Collection<Project> findJoinedProjectsByUserId(int userId);
	
	// List the projects in which a user can participate
	@Query("select r.project from Requirement r where r.project.state = \"recruiting\" " +
			" and r.group.id = ?1")
	Collection<Project> findAvailableProjectsByGroupId(int groupId);

}
